<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 200px;
            background: red;
            left: 0px;
            top:0px;
            display: block;
            position: absolute;
            display: none;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        // 1.触发鼠标右键点击的事件 ,事件源
        // 2.确定右键点击的位置
        // 3.把右键的框 left和top设置成 获取到的x和y的值
        var boxEle = document.querySelector(".box");
        document.oncontextmenu = function(e){
            boxEle.style.display = "block";
            // console.log("点击右键");
            var e = e || window.event;
            var x = e.clientX ;
            var y = e.clientY ;
            console.log(x,y);
            boxEle.style.left = x + "px";
            boxEle.style.top =  y + "px";
            e.preventDefault();
        }

        // 点击其他位置右键菜单消失
        document.onclick = function(){
            boxEle.style.display = "none";
        }


    </script>
</body>
</html>